#include<iostream>
#include <vector>
#include <cstdio>
#include <stack>
#include <algorithm>
#include <cstring>
using namespace std;

typedef long long ll;

int main()
{
	int n;
	cin >> n;
	vector<ll> arr(n + 2, -1);  //让最左边和最右边木板旁边还有木板
	vector<ll> l(n + 2), r(n + 2);//分别存储左右两边小于第i块木板的那个下标
	for (int i = 1; i <= n; i++) cin >> arr[i];
	
	stack<ll>s;
	for (int i = 1; i <= n + 1; i++) {
		while (!s.empty() && arr[i] < arr[s.top()]) {
			r[s.top()] = i;
			s.pop();
		}
		s.push(i);
	}
	while (!s.empty()) s.pop();
	for (int i = n; i >= 0; i--) {
		while (!s.empty() && arr[i] < arr[s.top()]) {
			l[s.top()] = i;
			s.pop();
		}
		s.push(i);
	}
	ll ans = 0;
	for (int i = 1; i <= n; i++) { //以每一块木板为基准值切出的最大面积
		ll height = arr[i], width = r[i] - l[i] - 1;
		ans = max(ans, height * width);
	}
	cout << ans << "\n";
	return 0;
}